home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / text / tex / amiweb2c.lha / AmiWeb2c-2.1 / texmf / pastex / rexx / Start_TeX.mg < prev    next >
Encoding:
Text File  |  1997-02-09  |  2.9 KB  |  139 lines

  1. /*
  2. ** AREXX $VER: Start_TeX.mg V1.42 (17.01.1993)
  3. **
  4. ** This AREXX script saves and compiles the current MicroGNUEmacs buffer.
  5. ** The only (optional) argument is the format to be used. A '?' formatname
  6. ** will interactively ask for the format to use.
  7. **
  8. ** A command is send to the TeX server to compile the file. Hence a return
  9. ** value of 0 does not mean that the file compiled well, but only that the
  10. ** command was sent to the server and replied to. 
  11. **
  12. ** AUTHOR: J\"org H\"ohle, March 91
  13. **
  14. ** BUGS: virtex doesn't like filenames with blanks (and ARexx parses them
  15. **       hardly too), so avoid them in file, directory *and* device names.
  16. **
  17. ** FILES: ENV:TEXFORMAT     default format used
  18. */
  19.  
  20. Options Results
  21.  
  22. PORTNAME = 'Start_TeX'
  23. SCRIPT   = 'TeX-server.rexx' /* no path required, message only */
  24.  
  25. /*
  26. ** 1: Ask interactively for the format name
  27. ** 0: Don't
  28. */
  29. If "" = GetClip("TEXQUERY") Then
  30.   ASKFORMAT = 0
  31. ELSE
  32.   ASKFORMAT = 1
  33.  
  34. Parse Arg FORMAT .
  35. If "?" = FORMAT Then Do
  36.   ASKFORMAT = 1
  37.   FORMAT    = ""
  38. End; Else If '&' = Left(FORMAT,1) Then
  39.   FORMAT = SubStr(FORMAT,2)
  40.  
  41. 'rexx-buffer' BUF
  42. /*
  43. ** BUF.2 is the complete filename (beware of spaces)
  44. */
  45.  
  46. If "TEX" ~= Upper(Right(BUF.2,3)) Then Do
  47. /*
  48. ** More foolproof : use namestruc() to verify extension
  49. */
  50.   If "LTX" ~= Upper(Right(BUF.2,3)) Then Do
  51.     'rexx-display "Sorry, filename must end in `tex' of `ltx''."'
  52.     Exit 5
  53.   End; Else Do
  54.     If ASKFORMAT = 1 Then
  55.       FORMAT = ""
  56.     Else
  57.       FORMAT = "lplain"
  58.   End
  59. End
  60.  
  61. 'save-buffer'
  62. /*
  63. ** Fails if file is write protected
  64. */
  65.  
  66. If Show('Port',PORTNAME) Then Do
  67.   ENVFORMAT = MyGetEnv("TEXFORMAT")
  68.   If "" = FORMAT Then Do
  69.     FORMAT = ENVFORMAT
  70.     If ASKFORMAT | "" = ENVFORMAT Then Do
  71.       If "" = FORMAT Then
  72.         FORMAT = 'plain'
  73.  
  74.       'rexx-request "Which format to use ? (default 'FORMAT') "'
  75. /*
  76. ** 0: answered
  77. ** 1: default
  78. ** 2: abort(^G)
  79. */
  80.       If 0 = RC Then
  81.         FORMAT = RESULT
  82.       Else If 1 < RC Then Do
  83.         'rexx-display ""'
  84.         Exit 5
  85.       End
  86.     End /* ASKFORMAT */
  87.   End   /* !FORMAT   */
  88.  
  89.   If FORMAT ~= ENVFORMAT Then
  90.     Call MySetEnv("TEXFORMAT",FORMAT)
  91.  
  92.   'rexx-display "Calling TeX server 'PORTNAME'."'
  93.  
  94. /*
  95. ** We want to free MG if the TeX server is just busy with another file
  96. */
  97.   'rexx-unlock'
  98. /*
  99. ** We free this MG port and get the name of a new one for later use
  100. */
  101.   FREEMG = RESULT
  102.  
  103.   Address Value PORTNAME
  104.   'compile' FORMAT BUF.2
  105.  
  106.   Address Value FREEMG
  107.   'rexx-display "TeX server called for file 'BUF.2'."'
  108.  
  109. End; Else Do
  110. /*
  111. ** The TeX server must be started first
  112. */
  113.   'rexx-display "The TeX server 'SCRIPT' is not running !"'
  114.   Exit 5
  115. End
  116.  
  117. Exit
  118.  
  119. /*
  120. ** When will ARexx supply GetEnv/SetEnv ?
  121. */
  122. MyGetEnv: Procedure
  123. Parse Arg NAME
  124.  
  125. If Open(TEMPFILE,"ENV:"||NAME,'r') Then Do
  126.   GIVES = Readln(TEMPFILE)
  127.   Call Close TEMPFILE
  128. End; Else
  129.   GIVES = ""
  130.  
  131. Return GIVES
  132.  
  133. MySetEnv: Procedure
  134. Parse Arg NAME,CONTENT
  135.  
  136. Address COMMAND "SetEnv" NAME CONTENT
  137.  
  138. Return
  139.